import { createRouter, createWebHistory } from 'vue-router'


const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      component: () => import('../views/HomeView.vue'),
      // 线下创建订单
    }, {
      path: '/reserve',
      name: 'reserve',
      component: () => import('../views/reserve.vue'),
      meta: { title: '线下预定', keepAlive: false }
      // 锁位
    }, {
      path: '/invitation',
      name: 'invitation',
      component: () => import('../views/invitation.vue'),
      meta: { title: '生成邀请函', keepAlive: false }
      // 邀请页面
    },{
      path: '/hideandseek',
      name: 'hideandseek',
      component: () => import('../views/Hideandseek.vue'),
      meta: { title: '隐藏座位', keepAlive: false }
    },{
      path: '/studentSeat',
      name: 'studentSeat',
      component: () => import('../views/studentSeat.vue'),
      meta: { title: '学生座位', keepAlive: false }
    }

  ],
})
// 全局前置守卫
router.beforeEach((to, from, next) => {
  // 检查目标路由是否有 meta.title
  if (to.meta && to.meta.title) {
    document.title = to.meta.title // 动态设置页面标题
  } else {
    document.title = '' // 如果没有设置 meta.title，则使用默认标题
  }
  next() // 确保导航继续
})

export default router
